home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
8206
/
8206.xpi
/
content
/
appspecific.js
next >
Wrap
Text File
|
2010-02-02
|
11KB
|
408 lines
function WisestampGetAppObject()
{
if (this.application)
return this.application;
if (WiseStampUtils.getAppType() == "Thunderbird")
this.application = new WisestampThunderbird();
else
this.application = new WisestampFirefox();
return this.application;
}
function WisestampFirefox()
{
}
WisestampFirefox.prototype =
{
onLoad: function ()
{
setTimeout(function (self){
document.addEventListener("ShowWisestampMenu", self.handleEvent, false, true); }, 1000, this);
var contextmenu = document.getElementById("contentAreaContextMenu");
if (contextmenu)
contextmenu.addEventListener("popupshowing", this.handleEvent, false);
},
openFirstRun: function ()
{
var firstrunURL = "http://www.wisestamp.com/first-steps";
this.openSite(firstrunURL);
},
openUpdate: function (currentVersion)
{
var updateURL = "http://www.wisestamp.com/version-history-upgraded#Version_" + currentVersion;
this.openSite(updateURL);
},
onUseSignature: function (event, aType, aPopup)
{
WiseStampUtils.log("[appspecific.js::Firefox::onUseSignature] >>>>> ");
if (typeof gContextMenu != 'undefined' && gContextMenu)
WisestampSignatureFactory.insertSignature(aType, gContextMenu.target.ownerDocument);
else if (this._contextEvent)
this.updateSiteFromWebmail(aType);
else
this.updateSiteFromChrome(aType);
},
handleEvent: function (event)
{
if (event.type == "popupshowing")
{
WisestampOverlay.app.showContextMenu(event);
} else if (event.type == "ShowWisestampMenu")
{
WisestampOverlay.app.showWisestampMenuForContent(event);
}
},
showContextMenu: function (event)
{
var item = document.getElementById("context-wisestamp");
item.hidden = !(WisestampOverlay.enabled && gContextMenu.isDesignMode);
},
updateSiteFromWebmail: function updateSiteFromWebmail_name(aType)
{
WiseStampUtils.log("[appspecific.js::updateSiteFromWebmail] >>>>> ");
var event = this._contextEvent;
if (event)
{
event.target.setAttribute("sigtype", aType);
var doc = event.target.ownerDocument;
var evt = doc.createEvent("Events");
evt.initEvent("UpdateWisestampSignature", true, false);
var canceled = !event.target.dispatchEvent(evt);
}
},
updateSiteFromChrome: function updateSiteFromChrome_name(aType)
{
WiseStampUtils.log("[appspecific.js::updateSiteFromChrome] >>>>> ");
if (typeof wisestamppreview != "undefined")
{
load();
} else
{
var PREFIX = "<!--WISESTAMP_SIG_START-->";
var SUFFIX = "<!--WISESTAMP_SIG_END-->";
function scanFrames(win)
{
for (var i = 0; i < win.frames.length; i++)
{
var f = win.frames[i];
if (f.document.designMode == "on")
{
var pattern = new RegExp(PREFIX.replace("!", "\!") + "(.|\n)*" + SUFFIX.replace("!", "\!"));
var sig = PREFIX + WisestampSignatureFactory.createSignature(null, aType) + SUFFIX;
var body = f.document.body;
if (body.innerHTML.match(pattern))
{
//Components.utils.reportError("sig in body");
body.innerHTML = body.innerHTML.replace(pattern, sig.replace('$','$$$$'));
} else
{
//Components.utils.reportError("inserted at end");
body.innerHTML = body.innerHTML + "<br><br>" + sig;
}
} else
{
scanFrames(f);
}
}
}
scanFrames(content);
}
},
showWisestampMenuForContent: function (event)
{
this._contextEvent = event;
var popup = document.getElementById("wisestampStatusPopup");
var x = event.screenX;
var y = event.screenY;
if (popup.openPopupAtScreen) //FF3
popup.openPopupAtScreen(x, y, false);
else
popup.showPopup(document.documentElement, x, y, "popup", "bottomleft", "topleft");
},
onPopupHidden: function (event)
{
this._contextEvent = null;
},
openHelp: function ()
{
this.openSite('http://www.wisestamp.com/usage-faq');
},
saveSignature: function (aData)
{
},
openSite: function (aURL)
{
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
if (win)
{
win.getBrowser().selectedTab = win.getBrowser().addTab(aURL);
win.focus();
} else
{
win = window.open(aURL);
win.focus();
}
},
enable: function ()
{
},
disable: function ()
{
},
getFooter: function (strings)
{
var footer = strings.GetStringFromName("wisestamp-footer-firefox");
return footer;
},
updateUI: function()
{
}
}
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
function WisestampThunderbird()
{
}
WisestampThunderbird.prototype =
{
get prefs()
{
if (typeof WisestampOverlay != "undefined")
return WisestampOverlay.prefs;
else
return WiseStampOptions.PREFS;
},
onLoad: function ()
{
this._saveSignatureToFile(this.prefs.getCharPref("type"));
var prefs = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefService);
prefs = prefs.getBranch("mail.");
prefs.setIntPref("default_html_action", 3);
},
openFirstRun: function ()
{
var firstrunURL = "http://www.wisestamp.com/first-steps-thunderbird";
this.openSite(firstrunURL);
},
openUpdate: function (currentVersion)
{
var updateURL = "http://www.wisestamp.com/version-history-upgraded#Version_" + currentVersion;
this.openSite(updateURL);
},
onUseSignature: function (event, aType, aPopup)
{
WiseStampUtils.log("[appspecific.js::Thunderbird::onUseSignature] >>>>> ");
},
openSite: function (aURL)
{
var ioservice = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
var uriToOpen = ioservice.newURI(aURL, null, null);
var extps = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"].getService(Components.interfaces.nsIExternalProtocolService);
extps.loadURI(uriToOpen, null);
},
openHelp: function ()
{
this.openSite('http://www.wisestamp.com/usage-faq');
},
_saveSignatureToFile: function (aType, aData)
{
WiseStampUtils.log("[appspecific.js::Thunderbird::_saveSignatureToFile] >>>>> ");
return;
var file = Components.classes["@mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties).
get("ProfD", Components.interfaces.nsIFile).
QueryInterface(Components.interfaces.nsILocalFile);
file.append("wisestampsignature.html");
// file is nsIFile, data is a string
var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"].
createInstance(Components.interfaces.nsIFileOutputStream);
// use 0x02 | 0x10 to open file for appending.
foStream.init(file, 0x02 | 0x08 | 0x20, 0666, 0);
// write, create, truncate
// In a c file operation, we have no need to set file mode with or operation,
// directly using "r" or "w" usually.
// if you are sure there will never ever be any non-ascii text in data you can
// also call foStream.writeData directly
var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"].
createInstance(Components.interfaces.nsIConverterOutputStream);
converter.init(foStream, "UTF-8", 0, 0);
converter.writeString(WisestampSignatureFactory.getFullSignatureHTML(aType, aData));
converter.close(); // this closes foStream
var mailprefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
mailprefs = mailprefs.getBranch("mail.identity.");
for (var index = 1; true; index++)
{
//mail.identity.id1.attach_signature
//var prefName="id"+index+".attach_signature";
try
{
mailprefs.getCharPref("id" + index + ".useremail");
mailprefs.setBoolPref("id" + index + ".attach_signature", this.prefs.getBoolPref("autoinsert") && this.prefs.getBoolPref("enabled"));
mailprefs.setCharPref("id" + index + ".sig_file-rel", "[ProfD]wisestampsignature.html");
mailprefs.setCharPref("id" + index + ".sig_file", file.path);
} catch(e)
{
break;
}
}
},
saveSignature: function (aType)
{
this._saveSignatureToFile(aType);
},
disable: function ()
{
var mailprefs = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefService);
mailprefs = mailprefs.getBranch("mail.identity.");
for (var index = 1; true; index++)
{
//mail.identity.id1.attach_signature
var prefName = "id" + index + ".attach_signature";
try
{
var val = mailprefs.getBoolPref(prefName);
var sigfile = "";
try
{
sigfile = mailprefs.getCharPref("id" + index + ".sig_file-rel");
} catch(e)
{
sigfile = mailprefs.getCharPref("id" + index + ".sig_file");
}
if (sigfile.indexOf("wisestampsignature.html") > 0)
{
mailprefs.setBoolPref(prefName, false);
} else
{
}
} catch(e)
{
break;
}
}
},
enable: function ()
{
var mailprefs = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefService);
mailprefs = mailprefs.getBranch("mail.identity.");
for (var index = 1; true; index++)
{
//mail.identity.id1.attach_signature
var prefName = "id" + index + ".attach_signature";
try
{
mailprefs.getBoolPref(prefName);
mailprefs.setBoolPref(prefName, this.prefs.getBoolPref("autoinsert") && this.prefs.getBoolPref("enabled"));
} catch(e)
{
break;
}
}
},
updateSiteFromChrome: function updateSiteFromChrome_name(aType)
{
WiseStampUtils.log("[appspecific.js::Thunderbird::updateSiteFromChrome] >>>>> ");
if (typeof wisestamppreview != "undefined")
{
load();
} else if (typeof WisestampCompose != "undefined")
{
WisestampCompose.onUseSignature(null, aType, null);
} else if (typeof WisestampOverlay != "undefined")
{
this._saveSignatureToFile(aType, null);
}
},
updateFramesFromChrome: function updateFramesFromChrome_name(aType)
{
WiseStampUtils.log("[appspecific.js::updateFramesFromChrome] >>>>> ");
var PREFIX = "<!--WISESTAMP_SIG_START-->";
var SUFFIX = "<!--WISESTAMP_SIG_END-->";
function scanFrames(win)
{
for (var i = 0; i < win.frames.length; i++)
{
var f = win.frames[i];
if (f.document.designMode == "on")
{
var pattern = new RegExp(PREFIX.replace("!", "\!") + "(.|\n)*" + SUFFIX.replace("!", "\!"));
var sig = PREFIX + WisestampSignatureFactory.createSignature(null, aType) + SUFFIX;
var body = f.document.body;
if (body.innerHTML.match(pattern))
{
body.innerHTML = body.innerHTML.replace(pattern, sig);
} else
{
body.innerHTML = body.innerHTML + "<br><br>" + sig;
}
} else
{
scanFrames(f);
}
}
}
var win = content ? content : window;
scanFrames(content);
},
getFooter: function (strings)
{
//var footer = strings.GetStringFromName("wisestamp-footer-thunderbird");
var footer = strings.GetStringFromName("wisestamp-footer-firefox");
return footer;
},
updateUI: function()
{
//document.getElementById("autoinsert_thread").setAttribute("disabled", "true");
}
}